﻿Imports System.DirectoryServices.AccountManagement
Imports System.DirectoryServices

Public Class Unlockaccount
    Public Shared Sub Unlock(struser)
        Using ctx As New PrincipalContext(ContextType.Domain)
            Using p = Principal.FindByIdentity(ctx, struser)
                If Not p Is Nothing Then
                    Dim objuser As New DirectoryEntry("LDAP://" & p.DistinguishedName)
                    objuser.Properties("LockOutTime").Value = 0
                    objuser.CommitChanges()
                End If
            End Using
        End Using
    End Sub
End Class